#include <cstdlib>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;

	set<int> node;
	auto cmp = [](auto &a, auto &b) { return a[2] > b[2]; };
	priority_queue<vector<int>, vector<vector<int>>, decltype(cmp)> pq(cmp);

	vector<vector<vector<int>>> gh(n + 1);
	for (int i = 0; i < m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		gh[u].push_back({ v, w });
		gh[v].push_back({ u, w });
	}
	for (auto &e : gh[1]) {
		pq.push({ 1, e[0], e[1] });
	}
	int ans = 0;
	set<int> nset = { 1 };
	while (!pq.empty()) {
		auto e = pq.top();
		pq.pop();
		if (nset.count(e[1]) == 0) {
			nset.insert(e[1]);
			ans += e[2];
			for (auto &v : gh[e[1]]) {
				pq.push({ e[1], v[0], v[1] });
			}
		}
	}
	if (nset.size() == n) {
		cout << ans << endl;
	} else {
		cout << "orz" << endl;
	}
	return 0;
}